package net.viservice.quartz.job;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PrintTimeJob implements Job {

	private static final Logger logger = LoggerFactory.getLogger(PrintTimeJob.class);
	private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.info("PrintTimeJob......");
		
		JobKey jobKey = context.getJobDetail().getKey();
		String currentTime = sdf.format(new Date());
		logger.info(jobKey.toString() + " ---> 执行时间:" + sdf.format(context.getFireTime()) + ",currentTime:" + currentTime);

		// 取出JobDataMap中存储的值
		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
		for (String key : jobDataMap.keySet()) {
			logger.info(jobKey.toString() + " jobDataMap ---> key:" + key + ",value" + jobDataMap.get(key));
		}
	}

}
